package com.lxmes.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSONObject;
import com.lxmes.business.service.ICcCaigouDetailService;
import io.swagger.annotations.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.lxmes.common.annotation.Log;
import com.lxmes.common.core.controller.BaseController;
import com.lxmes.common.core.domain.AjaxResult;
import com.lxmes.common.enums.BusinessType;
import com.lxmes.business.domain.CcCaigouMain;
import com.lxmes.business.service.ICcCaigouMainService;
import com.lxmes.common.utils.poi.ExcelUtil;
import com.lxmes.common.core.page.TableDataInfo;

/**
 * 采购Controller
 * 
 * @author ruoyi
 * @date 2022-06-11
 */
@Api(tags="采购单")
@RestController
@RequestMapping("/business/caigouMain")
public class CcCaigouMainController extends BaseController
{
    @Autowired
    private ICcCaigouMainService ccCaigouMainService;
    @Autowired
    private ICcCaigouDetailService ccCaigouDetailService;

    /**
     * 查询采购列表
     */
    @ApiOperation("单据主表列表")
    @PreAuthorize("@ss.hasPermi('business:caigouMain:list')")
    @GetMapping("/list")
    public TableDataInfo list(CcCaigouMain ccCaigouMain)
    {
        startPage();
        List<CcCaigouMain> list = ccCaigouMainService.selectCcCaigouMainList(ccCaigouMain);
        return getDataTable(list);
    }
    /**
     * 手机端采购单列表
     */
    @ApiOperation(value="采购单列表")
    //查询条件
    @ApiImplicitParams({
            @ApiImplicitParam(name = "queryParams", value = "采购单号、申请人、申请事由", paramType="query", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "pageSize", value = "分页大小",  required = true,paramType="query",  dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "pageNum", value = "当前页数",  required = true,paramType="query",   dataType = "int", dataTypeClass = Integer.class)
    })
    @ApiResponses({@ApiResponse(code=200,message = "0k",response = CcCaigouMain.class)})
  //  @PreAuthorize("@ss.hasPermi('mobile:caigouMain:list')")
    @GetMapping("/mobileList")
    public TableDataInfo mobileList(@RequestParam(value ="queryParams",required = false) String queryParams)
    {
        startPage();
        CcCaigouMain ccCaigouMain=new CcCaigouMain();
        ccCaigouMain.setQueryParams(queryParams);
        List<CcCaigouMain> list = ccCaigouMainService.selectCcCaigouMainList(ccCaigouMain);
        return getDataTable(list);
    }

    /**
     * 手机端采购单待审核列表
     */
    @ApiOperation(value="采购单待审核列表")
    //查询条件
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageSize", value = "分页大小",  required = true,paramType="query",  dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "pageNum", value = "当前页数",  required = true,paramType="query",   dataType = "int", dataTypeClass = Integer.class)
    })
    @ApiResponses({@ApiResponse(code=200,message = "0k",response = CcCaigouMain.class)})
   // @PreAuthorize("@ss.hasPermi('mobile:caigouMain:stateList')")
    @GetMapping("/mobileStateList")
    public TableDataInfo mobileStateList()
    {
        startPage();
        CcCaigouMain ccCaigouMain=new CcCaigouMain();
        ccCaigouMain.setShenheState(0L);
        List<CcCaigouMain> list = ccCaigouMainService.selectCcCaigouMainList(ccCaigouMain);
        return getDataTable(list);
    }


    /**
     * 导出采购列表
     */
    @PreAuthorize("@ss.hasPermi('business:caigouMain:export')")
    @Log(title = "采购", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CcCaigouMain ccCaigouMain)
    {
        List<CcCaigouMain> list = ccCaigouMainService.selectCcCaigouMainList(ccCaigouMain);
        ExcelUtil<CcCaigouMain> util = new ExcelUtil<CcCaigouMain>(CcCaigouMain.class);
        util.exportExcel(response, list, "采购数据");
    }

    /**
     * 获取采购详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:caigouMain:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(ccCaigouMainService.selectCcCaigouMainById(id));
    }
    /**
     * 手机端获取采购详细信息
     */
    @ApiOperation(value="采购单详细信息")
    @ApiImplicitParam(name = "danhao", value = "采购单单号", required = true, dataType = "String", paramType = "path", dataTypeClass = String.class)
    @GetMapping(value = "/getMobilecaigouMain/{danhao}")
    public AjaxResult mobileGetInfo(@PathVariable("danhao") String  danhao)
    {
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("caigouMain",ccCaigouMainService.selectCcCaigouMainByDanHao(danhao));
        jsonObject.put("caigouDetail", ccCaigouDetailService.selectCcCaigouDetailByDanHao(danhao));
        return AjaxResult.success(jsonObject);
    }

    /**
     * 手机端新增采购
     */
    @ApiOperation(value="采购单新增")
   // @PreAuthorize("@ss.hasPermi('mobile:caigouMain:add')")
    @Log(title = "采购", businessType = BusinessType.INSERT)
    @PostMapping("/mobileAdd")
    public AjaxResult mobileAdd(@RequestBody CcCaigouMain ccCaigouMain)
    {
        return toAjax(ccCaigouMainService.insertCcCaigouMain(ccCaigouMain));
    }

    /**
     * 新增采购
     */
    @PreAuthorize("@ss.hasPermi('business:caigouMain:add')")
    @Log(title = "采购", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CcCaigouMain ccCaigouMain)
    {
        return toAjax(ccCaigouMainService.insertCcCaigouMain(ccCaigouMain));
    }

    /**
     * 手机端采购单审核
     */
    @ApiOperation(value="采购单审核",tags = "0-未审核 1-审核   2-驳回")
    //@PreAuthorize("@ss.hasPermi('mobile:caigouMain:edit')")
    @Log(title = "采购单审核", businessType = BusinessType.UPDATE)
    @PutMapping("/mobileEdit")
    public AjaxResult mobileEdit(@RequestBody CcCaigouMain ccCaigouMain)
    {
        return toAjax(ccCaigouMainService.updateMobileCcCaigouMain(ccCaigouMain));
    }


    /**
     * 修改采购
     */
    @Log(title = "采购", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CcCaigouMain ccCaigouMain)
    {
        return toAjax(ccCaigouMainService.updateCcCaigouMain(ccCaigouMain));
    }
    /**
     * 修改采购
     */
    @Log(title = "采购状态修改", businessType = BusinessType.UPDATE)
    @PutMapping("/updateCaigouMainState")
    public AjaxResult updateCaigouMainState(@RequestBody CcCaigouMain ccCaigouMain)
    {
        return toAjax(ccCaigouMainService.updateCaigouMainState(ccCaigouMain));
    }


    /**
     * 删除采购
     */
    @PreAuthorize("@ss.hasPermi('business:caigouMain:remove')")
    @Log(title = "采购", businessType = BusinessType.DELETE)
	@DeleteMapping("/{danhao}")
    public AjaxResult remove(@PathVariable String danhao)
    {
        return toAjax(ccCaigouMainService.deleteCcCaigouMainByDanhao(danhao));
    }
}
